package com.hiultra.archive.controller.device;

import com.hiultra.archive.device.shelve.ShelvesManager;
import com.hiultra.archive.domain.ArcAlarm;
import com.hiultra.archive.service.IArcAlarmService;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备密集架-操作
 */
@Api(tags="设备-密集架")
@RestController
@RequestMapping("/device/shelve")
public class ArcDeviceShelveController extends BaseController
{
    @Autowired
    private IArcAlarmService arcAlarmService;

    @Autowired
    private ShelvesManager shelvesManager;
    /**
     * 开架
     */
    @ApiOperation(value = "开架", notes = "开架")
//    @PreAuthorize("@ss.hasPermi('devcie:shelve:open')")
    @GetMapping("/open")
    public AjaxResult open(String ip,String warehouseCode,String areaCode,String area,String faceNo,int columnNo)
    {
        shelvesManager.open(ip,warehouseCode,areaCode,area,faceNo,columnNo,null);

        return AjaxResult.success();
    }

    /**
     * 导出报警列表
     */
    @ApiOperation(value = "", notes = "导出报警列表")
    @PreAuthorize("@ss.hasPermi('environment:alarm:export')")
    @Log(title = "报警", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArcAlarm arcAlarm)
    {
        List<ArcAlarm> list = arcAlarmService.selectArcAlarmList(arcAlarm);
        ExcelUtil<ArcAlarm> util = new ExcelUtil<ArcAlarm>(ArcAlarm.class);
        util.exportExcel(response, list, "报警数据");
    }

    /**
     * 获取报警详细信息
     */
    @ApiOperation(value = "获取报警详细信息", notes = "获取报警详细信息")
    @PreAuthorize("@ss.hasPermi('environment:alarm:query')")
    @GetMapping(value = "/{alarmId}")
    public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId)
    {
        return AjaxResult.success(arcAlarmService.selectArcAlarmByAlarmId(alarmId));
    }

    /**
     * 新增报警
     */
    @ApiOperation(value = "新增报警", notes = "新增报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:add')")
    @Log(title = "报警", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArcAlarm arcAlarm)
    {
        return toAjax(arcAlarmService.insertArcAlarm(arcAlarm));
    }

    /**
     * 修改报警
     */
    @ApiOperation(value = "修改报警", notes = "修改报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:edit')")
    @Log(title = "报警", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArcAlarm arcAlarm)
    {
        return toAjax(arcAlarmService.updateArcAlarm(arcAlarm));
    }

    /**
     * 删除报警
     */
    @ApiOperation(value = "删除报警", notes = "删除报警")
    @PreAuthorize("@ss.hasPermi('environment:alarm:remove')")
    @Log(title = "报警", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmIds}")
    public AjaxResult remove(@PathVariable Long[] alarmIds)
    {
        return toAjax(arcAlarmService.deleteArcAlarmByAlarmIds(alarmIds));
    }
}
